package com.lanlian.cayman.adapter;

import android.support.annotation.Nullable;
import android.text.Html;
import android.util.SparseBooleanArray;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lanlian.cayman.R;
import com.lanlian.commonlib.bean.QuestionInfo;
import com.lanlian.commonlib.common.SystemConfig;

import java.util.List;

/**
 * <pre>
 *     author : huxiaobo
 *     e-mail : huxiaobo@xlanlian.com
 *     date   : 2018/8/15 16:55
 *     desc   : 常见问题Adapter
 *     version: 1.0
 * </pre>
 */
public class QuestionAdapter extends BaseQuickAdapter<QuestionInfo, BaseViewHolder> {

    public SparseBooleanArray booleanArray = new SparseBooleanArray();

    public QuestionAdapter(int layoutResId, @Nullable List<QuestionInfo> data) {
        super(layoutResId, data);
        for (QuestionInfo datum : data) {
            booleanArray.put(data.indexOf(datum), false);
        }
    }

    @Override
    protected void convert(BaseViewHolder helper, QuestionInfo item) {
        helper.setText(R.id.tv_question, (helper.getLayoutPosition() + 1) + "、" + item.getIssueHeadline())
                .setText(R.id.tv_answer, Html.fromHtml(item.getIssueContent()))
                .addOnClickListener(R.id.tv_question);
        if (booleanArray.get(helper.getLayoutPosition())) {
            ((TextView)helper.getView(R.id.tv_question)).setCompoundDrawablesWithIntrinsicBounds(0, 0, R.mipmap.icon_arrow_up_gray, 0);
            helper.setGone(R.id.tv_answer, true);
        } else {
            ((TextView)helper.getView(R.id.tv_question)).setCompoundDrawablesWithIntrinsicBounds(0, 0, R.mipmap.icon_arrow_down_gray, 0);
            helper.setGone(R.id.tv_answer, false);
        }
    }

}
